package Demo01;


class Animal {
    public static int count = 0;

    /*    synchronized public void increase() {
            count++;
        }*/
/*    public void increase() {
        synchronized (this) {
            count++;
        }
    }*/
/*    synchronized public static void increase() {
        count++;
    }*/
    public static void increase() {
        synchronized (Animal.class) {
            count++;
        }
    }
}

public class Demo2 {
    public static void main(String[] args) throws InterruptedException {
        Animal animal = new Animal();
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 100000; i++) {
                animal.increase();
            }
        });
        Thread t2 = new Thread(() -> {
            for (int i = 0; i < 100000; i++) {
                animal.increase();
            }
        });

        t1.start();
        t2.start();
        t1.join();
        t2.join();

        System.out.println(animal.count);
    }
}
